import { Tools } from "../../common/Tools";
import { AudioManager1 } from "../../manager/AudioManager1";
import { EventManager } from "../../manager/EventManager";
import LevelBase from "../../LevelBase";
import { EVENT_NAME_ENUM } from "../../base/EnumIndex";

const { ccclass, property } = cc._decorator;

@ccclass
export default class CardItem_18 extends cc.Component {


    // LIFE-CYCLE CALLBACKS:

    @property(cc.Node)
    par: cc.Node = null;
    /**卡牌容器 */
    @property(cc.Node)
    cardContent: cc.Node = null;
    @property(cc.Node)
    /**背景动画 */
    ani: cc.Node = null;

    // onLoad () {}

    private isClick: boolean = false;

    start() {
        this.node.on("click", () => {
            if (this.isClick) return;
            AudioManager1.stopAllAudio();
            this.isClick = true;
            let copy = cc.instantiate(this.node);
            copy.getComponent(CardItem_18).isClick = true;
            let pos = Tools.getToNodePosForNode(this.node, this.par);
            this.par.addChild(copy);
            copy.setPosition(pos.x, pos.y);
            let card2 = copy.getChildByName("ka_1").getChildByName("ka_2");
            cc.tween(copy).to(0.5, {
                x: 0,
                y: 0,
                scale: 4
            }).to(0.2, {
                scaleX: 0
            }).call(() => {
                card2.active = true;
            }).to(0.2, {
                scaleX: 4
            }).delay(1).call(() => {
                this.node.getChildByName("ka_1").getChildByName("ka_2").active = true;
                copy.active = false;
                this.cardContent.active = false;
                this.ani.active = true;
                let levelBase = cc.director.getScene().getChildByName("Canvas").getComponentInChildren(LevelBase);
                let musicId = this.node.getSiblingIndex() + 1;
                EventManager.ins.emit(EVENT_NAME_ENUM.FINISH_INTER_TWEEN, "choseCard_" + musicId);
                levelBase.runNodeTween(levelBase.node, levelBase.getInterTwForName("music_" + musicId).interTween);
                // EventManager.ins.emit(EVENT_NAME_ENUM.FINISH_INTER_TWEEN, "showTipBtn_" + musicId);
            }).start();
        })
    }

    // update (dt) {}
}
